﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Server.Biz;
using Server.Model;

namespace TestProjectForService
{
    [TestClass]
    public class UnitTest1
    {
        
        [TestMethod]
        public void TestNoCommand()
        {
            CommandService service = new CommandService();
            Status? status = service.UpdateStatusAndGetLatestedCommand(Server.Model.Status.Unlock, 100, 888, "Lorry");
            if (status != null)
            {
                service.UpdateStatusAndGetLatestedCommand(status.Value, 100, 888, "Lorry");
            }

            Assert.IsNull(service.UpdateStatusAndGetLatestedCommand(status.Value, 100, 888, "Lorry"));
        }

        [TestMethod]
        public void TestExistNewCommand()
        {
            CommandService service = new CommandService();
            service.SetCommand(Server.Model.Status.Lock, 100, 888, "Lorry");
            Status? newStatus = service.UpdateStatusAndGetLatestedCommand(Server.Model.Status.Unlock, 100, 888, "Lorry");

            Assert.AreEqual(true, newStatus.Value == Status.Lock);
        }

        [TestMethod]
        public void TestExistProcessingCommandNotMatch()
        {
            CommandService service = new CommandService();
            Status? newStatus = service.UpdateStatusAndGetLatestedCommand(Status.Unlock, 100, 888, "Lorry");
            Assert.IsTrue(newStatus.Value == Status.Lock);
        }

        [TestMethod]
        public void TestExistProcessingCommandMatch()
        {
            CommandService service = new CommandService();
            Status? newStatus = service.UpdateStatusAndGetLatestedCommand(Status.Lock, 100, 888, "Lorry");
            Assert.IsTrue(newStatus == null);
        }
    }
}
